# 删除桥接对应的网卡
del_brctl(){
	nic_array=($(ip a | grep -E "state (UP|DOWN)" | grep -Ev 'lo|\.|virbr|@|docker' | cut -d':' -f2,3 | awk '{print $1,$8}' | grep "br" | grep -Ev "^br" | cut -d: -f1));
	br_array=($(ip a | grep -E "state (UP|DOWN)" | grep -Ev 'lo|\.|virbr|@|docker' | cut -d':' -f2,3 | awk '{print $1,$8}' | grep "br" | grep -Ev "^br" | cut -d: -f2));
	for i in $(seq ${#nic_array[*]})
	do
		j=`expr $i - 1`;
		`brctl delif ${br_array[$j]} ${nic_array[$j]}`
	done
}


# 增加桥接
add_brctl(){
	cat /etc/ppp/data/conf/config.json | grep -E "username|nic" | tr '":,' " " | awk '{print$2}' | xargs -n2 > tmp1.tmp
	j=0
	declare -A wan_username
	for i in `./op_ik.py check | grep username | cut -d"," -f2,5 | tr ",:" " " | awk '{print $1,$3}' | sort -t" " -k1,1 -u | awk '{print $2}'`
	do
		wan_username["br${j}"]="$i"
		j=`expr $j + 1`
	done

	for i in `seq 0 $(expr ${#wan_username[*]} - 1)`
	do
		brctl addif br$i `cat tmp1.tmp | grep ${wan_username["br$i"]} | cut -d" " -f2`
	done
}

main(){
	if [ $# != 1 ];then
		echo "请输入进行的操作:0 删除桥接，1 增加桥接"
	else
		if [ $1 == 1 ] || [ $1 == 2 ];then
			if [ $1 == 1 ];then
				echo "del_brctl"
			elif [ $1 == 2 ];then
				echo "add_brctl" 
			else
				echo "请输入进行的操作:0 删除桥接，1 增加桥接"
			fi
		fi
	fi
}

main $@